export const upload = () => {
  return new Promise((resolve, reject) => {
    let el = document.querySelector("#sInp");
    el && el.remove();
    let inp = document.createElement("input");
    inp.type = "file";
    inp.id = "sInp";
    inp.style='display:none';
    inp.setAttribute("accept", "image/*");
    document.body.appendChild(inp);
    inp.addEventListener("change", (e) => {
      let file = e.target.files[0];
      let base64String;
      if (file) {
        const reader = new FileReader();
        reader.onloadend = async function () {
          base64String = await reader.result; // 获取 Base64 字符串
          let type = file.type.split("/")[0];
          let suffix = file.type.split("/")[1];
          resolve({
            file,
            base64String,
            type,
            suffix,
          });
        };
        // 开始读取文件
        reader.readAsDataURL(file);
      }
    });
    inp.click();
  });
};
